﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mobile;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.UI.MobileControls;
using DECOR.BL.BE;
using DECOR.BL.BC;
using System.Collections.Generic;

namespace MobileWebApp
{
    public partial class stock : MobilePage
    {
        List<GenericBE> _lvLstGeneric;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this._lvLstGeneric = CentroBC.Instance.listar();
                this._lvLstGeneric.RemoveAt(this._lvLstGeneric.Count - 1);
                cmbCentro.DataSource = this._lvLstGeneric;
                cmbCentro.DataTextField = "Descripcion";
                cmbCentro.DataValueField = "Codigo";
                cmbCentro.DataBind();
                cmbCentro.SelectedIndex = 0;

                string codLote = cmbCentro.Items[cmbCentro.SelectedIndex].Value;
                this._lvLstGeneric = AlmacenBC.Instance.listar(codLote);
                this._lvLstGeneric.RemoveAt(this._lvLstGeneric.Count - 1);
                if (this._lvLstGeneric.Count == 0) { GenericBE obj = new GenericBE(); obj.Codigo = ""; obj.Descripcion = "Ninguno"; this._lvLstGeneric.Add(obj); }
                cmbAlmacen.DataSource = this._lvLstGeneric;
                cmbAlmacen.DataTextField = "Descripcion";
                cmbAlmacen.DataValueField = "Codigo";
                cmbAlmacen.DataBind();
                cmbAlmacen.SelectedIndex = 0;
            }
        }

        protected void cmbCentro_SelectedIndexChanged(object sender, EventArgs e)
        {
            string codLote = cmbCentro.Items[cmbCentro.SelectedIndex].Value;
            this._lvLstGeneric = AlmacenBC.Instance.listar(codLote);
            this._lvLstGeneric.RemoveAt(this._lvLstGeneric.Count - 1);
            if (this._lvLstGeneric.Count == 0) { GenericBE obj = new GenericBE(); obj.Codigo = ""; obj.Descripcion = "Ninguno"; this._lvLstGeneric.Add(obj); }
            cmbAlmacen.DataSource = this._lvLstGeneric;
            cmbAlmacen.DataTextField = "Descripcion";
            cmbAlmacen.DataValueField = "Codigo";
            cmbAlmacen.DataBind();
            cmbAlmacen.SelectedIndex = 0;
        }

        protected void btnVerStock_Click(object sender, EventArgs e)
        {
            StockBE pObjStock = new StockBE();
            pObjStock.CodMaterial = txtCodMaterial.Text.Trim().PadLeft(18,'0');

            List<StockBE> lstStock = StockBC.Instance.buscarStock(pObjStock);
            lstStock.RemoveAll(X => X.CodLote.Equals(""));
            olstStock.DataSource = lstStock;
            olstStock.DataBind();
        }
    }
}
